<template>
	<view class="list-view">
		<view class="top-bar"><uni-navbar :show="show" @click-show="show = !show" :fixed="true" :back="true" color="#fff" title="统计分析"></uni-navbar></view>

		<view class="filter-box" v-if="show">
			<view class="form-box">
				<u-form ref="uForm">
					<u-form-item class="form-item" label="类型">
						<u-input v-model="type" type="select" :select-open="typeShow" placeholder="请选择类别" @click="typeShow = true" />
						<u-select :list="typeList" v-model="typeShow" @confirm="typeConfirm"></u-select>
					</u-form-item>
					<u-form-item class="form-item" label="年度">
						<date-time-picker placeholder="请选择年度" :defaultValue="statistics.time" fields="year" :old="true" @change="yearChange"></date-time-picker>
					</u-form-item>
				</u-form>
			</view>
			<view class="fiexd-btm">
				<view class="flex-box">
					<u-button class="form-btn" type="default" @click="resert">清除</u-button>
					<u-button class="form-btn" type="error" @click="filter">确定</u-button>
				</view>
			</view>
		</view>

		<u-tabs class="uTabs" :list="tabsList" bgColor="#e5231a" inactiveColor="#fff" activeColor="#fff" barWidth="114" :current="tabsCurrent" @change="tabsChange" :is-scroll="false"></u-tabs>

		<view class="tab-box">
			<view class="search-filter" @click="show = !show"><view>筛选</view></view>
		</view>

		<view class="table-box">
			<u-table class="table-inner" border-color="#F8F8F8" :key="tabIndex">
				<u-tr>
					<u-th width="300rpx" v-if="tabsCurrent == 0">类型</u-th>
					<u-th width="300rpx" v-else>组织部门</u-th>
					<u-th width="140rpx">总数</u-th>
					<u-th>占全部总数%</u-th>
				</u-tr>
				<view class="table-cell" v-for="(item, index) of statisticsList" :key="index">
					<u-tr>
						<u-td width="300rpx">{{ item.key1 }}</u-td>
						<u-td width="140rpx">{{ item.key2 }}</u-td>
						<u-td>{{ item.key3 }}</u-td>
					</u-tr>
				</view>
			</u-table>
		</view>
	</view>
</template>

<script>
import dateTimePicker from '@/components/uni-datetime-picker';
import { mapState } from 'vuex';
export default {
	components: {
		dateTimePicker
	},
	data() {
		return {
			scrollTop: 0,
			show: false,
			tabIndex: 10,
			tabsCurrent: 0,
			tabsList: [
				{
					name: '类型统计',
					value: 0
				},
				{
					name: '组织部门统计',
					value: 1
				}
			],
			type: '会议',
			typeShow: false,
			typeList: [
				{
					value: 'huiyi',
					label: '会议'
				},
				{
					value: 'huodong',
					label: '活动'
				}
			],

			statisticsList: [],
			statistics: {
				type: '类型',
				remark1: 'huiyi',
				time: ''
			}
		};
	},
	onLoad() {
		this.loadLogin();
		this.loadData();
	},
	onReachBottom() {
		if (this.loading == 'loadmore') this.loadData('add');
	},
	onPageScroll(res) {
		this.scrollTop = res.scrollTop;
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;
			} else {
				this.$logout();
			}
		},
		loadData(type = 'add') {
			let url = '/huiyihuodong/hyhd-meeting/tongji';
			let data = {
				currentUserId: this.userId,
				clientCode: this.clientCode,
				...this.statistics
			};
			this.$request(url, data, {
				load: true
			}).then((res) => {
				this.statisticsList = res.data;
			});
		},
		tab(e) {
			this.tabIndex = e;
			this.loadData('refresh');
		},
		tabsChange(index) {
			this.tabsCurrent = index;
			if (index == 0) {
				this.statistics.type = '类型';
			} else {
				this.statistics.type = '部门';
			}
			this.resert();
		},
		yearChange({ date }) {
			this.statistics.time = date.year.toString();
		},
		typeConfirm(e) {
			this.type = e[0].label;
			this.statistics.remark1 = e[0].value;
		},
		filter() {
			this.show = false;
			this.tabIndex = this.tabsCurrent * 10 + 10;
			this.statisticsList = [];
			this.loadData('refresh');
		},
		resert() {
			this.show = false;
			this.statistics.time = '';
			this.tabIndex = this.tabsCurrent * 10 + 10;
			this.statisticsList = [];
			this.loadData('refresh');
		}
	}
};
</script>

<style lang="scss">
.tab-box {
	padding: 18rpx 0;
	font-size: 14px;
	color: #666;
	line-height: 60rpx;
	overflow-x: auto;
	background-color: #fff;

	& + .tab-box {
		padding-top: 0;
	}

	.search-filter {
		margin: 0 30rpx;
		width: 120rpx;
		height: 60rpx;
		float: right;
		text-align: center;
		border-radius: 6rpx;
		background-color: #e6e7e8;
	}

	.title {
		padding: 0 30rpx;
		float: left;
		font-weight: bold;
	}
}

.tab-nav {
	padding: 0 20rpx;
	border: 0;
	background-color: #fff;

	&:after {
		content: '';
		flex-shrink: 0;
		width: 20rpx;
		height: 1rpx;
	}

	.tab-item {
		flex-shrink: 0;
		margin: 0 10rpx;
		padding: 0 10rpx;
		height: 60rpx;
		color: #666;
		text-align: center;
		border-radius: 6rpx;
		background-color: #e6e7e8;
	}

	.tab-item.active {
		font-weight: bold;
		color: #fff;
		background-color: #e5231a;
	}
}

.filter-box {
	position: fixed;
	left: 0;
	top: 0;
	bottom: 0;
	right: 0;
	z-index: 998;
	background-color: #fff;
}

.table-box {
	clear: both;

	.name {
		display: flex;
		flex-wrap: nowrap;
		justify-content: center;

		text {
			color: #333;
			width: 260rpx;
			text-align: left;
		}
	}

	text {
		color: #0196fa;
	}

	.break-all {
		word-break: break-all;
	}

	image {
		margin-right: 20rpx;
		width: 80rpx;
		height: 80rpx;
	}
}

.form-box {
	.form-item {
		@include mp-flex;
	}
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
